@extends('Admin.base')
@section('css')
    <link rel="stylesheet" href="/Admin/layuiadmin/css/extend/formSelects-v4.css" media="all">
@endsection
@section('style')

@endsection
@section('content')
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item layui-row">

                <div class="layui-inline layui-col-xs3 layui-col-sm3 layui-col-md3">
                    <label class="layui-form-label">申请时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="datetime" class="layui-input" id="datetime-pick" placeholder=" - " readonly>
                    </div>
                </div>

                <div class="layui-inline layui-col-xs2 layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">所在城市</label>
                    <div class="layui-input-block">
                        <input type="text" name="region" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-col-xs2 layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-col-xs2 layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-btn-group layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-input-block layuiadmin-btn-admin" lay-submit lay-filter="LAY-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-table" lay-filter="LAY-table"></table>
            <script type="text/html" id="toolbarDemo">
              <div class="layui-btn-container">
                <button class="layui-btn" lay-event="export">导 出</button>
              </div>
            </script>



        </div>
    </div>
@endsection

@section('script')
    <script src="/js/ajax.js"></script>
    <script>
        layui.use(['form', 'table', 'formSelects', 'laydate'], function(){
            var $ = layui.$
                ,form = layui.form
                ,table = layui.table
                ,formSelects = layui.formSelects
                ,laydate = layui.laydate;

            //日期时间范围
            laydate.render({
                elem: '#datetime-pick'
                ,type: 'datetime'
                ,range: '~'
            });


            table.render({
                elem: '#LAY-table'
                ,toolbar: '#toolbarDemo'
                ,url: "{{url('/admin/partner/table')}}"
                ,method: "post"
                ,page: true //开启分页
                ,limit:30
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'id', title:'序号', width:80, fixed: 'left', unresize: true, sort: true}
                    ,{field: 'name', title: '姓名'}
                    ,{field: 'phone', title: '手机'}
                    ,{field: 'created_at', title: '申请时间'}
                    ,{field: 'region', title: '所在城市'}
                ]]

            });

            //监听工具条
            table.on('toolbar(LAY-table)', function(obj){
                switch(obj.event){
                  //判断是否为导出按钮
                  case 'export':
                    var field = obj.config.where;
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    var id_str = '';
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            id_str += data[i].id + ',';
                        }
                        id_str = id_str.substr(0, id_str.length-1);
                    }

                    layer.prompt({
                        id_str:id_str,
                        formType: 0,
                        value: '',
                        title: '请输入文件名称',
                        btn:['导出','取消']
                    }, function(value, index, elem){
                        if(value == '' || value == undefined){
                            layer.msg('请输入文件名称');
                        }else{
                            field.filename = value;
                            field.ids = id_str;
                            $.ajax({
                                url: '/admin/partner/export'
                                , type: 'POST'
                                , dataType: 'json'
                                , data: field
                                , success: function (ret) {
                                    if (ret.hasOwnProperty('code') && ret.code == 200) {
                                        layer.msg(ret.message,{icon: 1,time:2000});
                                        return false;
                                    }
                                    layer.msg(ret.message,{icon:2});
                                }
                            });
                            layer.close(index);
                        }

                    });
                  break;
                }

            });

            //监听搜索
            form.on('submit(LAY-search)', function(data){
                var field = data.field;
                //执行重载
                table.reload('LAY-table', {
                    where: field,page: {curr: 1}
                });
            });
        });
    </script>

@endsection